package com.linjacy.container.product.controller;

import com.alibaba.fastjson.JSON;
import com.linjacy.common.utils.PageUtils;
import com.linjacy.common.utils.R;
import com.linjacy.container.product.service.LogisticsService;
import com.linjacy.container.product.service.TransporterService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.Map;
import java.util.concurrent.TimeUnit;

@RestController
@Slf4j
@RequestMapping("product/logistics/info")
public class LogisticsController {
    @Autowired
    private LogisticsService logisticsService;
    @Autowired
    StringRedisTemplate redisTemplate;
    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = logisticsService.queryPage(params);
        log.info("此刻的数据为【{}】",page.getList());
        redisTemplate.opsForValue().set("MyTestListen", JSON.toJSONString(Arrays.asList(page.getList())),15, TimeUnit.SECONDS);
        return R.ok().put("page", page);
    }

    /**
     * 更新物流状态
     * @param params
     * @return
     */
    @RequestMapping("/update")
    public R updateLogistics(@RequestParam Map<String, Object> params){
        logisticsService.updateStatus(params);
        return R.ok();
    }
}
